package com.sos.widget.binding;

import android.content.res.ColorStateList;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.BindingAdapter;

import com.hjq.bar.TitleBar;

public class TitleBarBinding {

    @BindingAdapter(value = {"saas_title", "saas_leftVisibility", "saas_titleColor","saas_titleBackGroup"}, requireAll = false)
    public static void setTitleBar(TitleBar titleBar, String title, Boolean leftVisibility, int titleColor,int titleBackGroup) {
        if (titleBar != null) {
            if (!TextUtils.isEmpty(title)) {
                titleBar.setTitle(title);
            }
            if (leftVisibility != null) {
                titleBar.getLeftView().setVisibility(leftVisibility ? View.VISIBLE : View.GONE);
            }
            if (titleColor != 0) {
                titleBar.setTitleColor(titleColor);
                titleBar.getLeftView().setCompoundDrawableTintList(ColorStateList.valueOf(titleColor));
            }
            if(titleBackGroup!=0){
                titleBar.setBackgroundColor(titleBackGroup);
            }
        }
    }
}